<template>
	<view class="wrap">
		<u-notice-bar :text="hitn"></u-notice-bar>
		
		<view class="content formWrap textLength">
			<view class="title" style="margin-top: 0;">逾期尚未支付合同情况</view>
			
			<u-form :model="formData" ref="uForm" :rules="rules">
				<u-form-item v-if="formKeys.isodsmepay" label="是否存在《保障中小企业款项支付条例》（国务院令第728号）规定的逾期尚未支付中小企业款项的情形" prop="isodsmepay" required label-width="auto" borderBottom>
					<u-radio-group v-model="formData.isodsmepay" placement="row">
						<u-radio v-for="item,index in stateRanges" :key="index" :label="item.text" :name="item.value" :activeColor="bgColor"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item v-if="formKeys.odsmepayconnum" label="逾期尚未支付中小企业款项的合同数量" prop="odsmepayconnum" required label-width="auto" borderBottom>
					<u-input v-model="formData.odsmepayconnum" placeholder="请输入" type="number" border="none">
						<u--text
							text="个"
							slot="suffix"
						></u--text>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.odsmepayconam" label="逾期尚未支付中小企业款项的合同金额" prop="odsmepayconam" required label-width="auto" borderBottom>
					<u-input v-model="formData.odsmepayconam" placeholder="请输入" type="number" border="none">
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.filinstr" label="填报说明 (内容不超过500字)" prop="filinstr" label-width="auto">
					<u--textarea v-model="formData.filinstr" placeholder="请输入内容" maxlength="500" ></u--textarea>
				</u-form-item>
			</u-form>
			
		</view>
		<view class="submitBtn_bc"></view>
		<view class="submitBtn_ubtn">
			<u-button :disabled="!$util.submitState(year,state)" @click="submit()">提交</u-button>
		</view>
		
	</view>
</template>

<script>
export default {
	data(){
		return{
			minFormName: 'overduepay', //小表单类型名
			regnoInfo: this.$store.state.regnoInfo,
			year: '',
			state: '',
			bgColor: this.$config.bgColor,
			
			hitn: '注: 如企业履行支付义务，6月30日后允许对逾期尚未支付中小企业款项信息进行修改。',
			stateRanges: [
				{text: '是',value: '1'},
				{text: '否',value: '2'}
			],
			formData: {
				isodsmepay: '',
				odsmepayconnum: '',
				odsmepayconam: '',
				filinstr: '',
			},
			rules: {},
			rulesAll: {
				isodsmepay: this.$typeData.ruleData.disRule,
				odsmepayconnum: this.$typeData.ruleData.peopleRule,
				odsmepayconam: this.$typeData.ruleData.moneyRule,
			},
			formKeys: {},
			
		}
	},
	onLoad(option) {
		this.year = option.year;
		this.state = option.state;
		this.getFormKey();
		this.getFormData();
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules)
	},
	methods:{
		// 获取小表单数据
		getFormData(){
			let url = this.$typeData.minFormUrl.get(this.minFormName);
			if(!url){
				uni.showModal({
					title: '暂无接口'
				})
				return;
			}
			this.$http.sendRequest({
				url: url,
				data: {
					regno: this.regnoInfo.regno,
					ancheyear: this.year
				}
			})
			.then(res=>{
				console.log('接口返回',res.data);
				let data = res.data[0];
				let keys = Object.keys(this.formKeys);
				keys.forEach(item=>{
					this.formData[item] = data[item];
				})
				console.log(789789,this.formData);
			})
			.catch(err=>{})
		},
		//获取小表单拥有字段
		getFormKey(){
			let formKeys = this.$util.getFormKeys(this.minFormName,this.regnoInfo.enttype);
			this.formKeys = formKeys;
			let keys = Object.keys(formKeys);
			keys.forEach(item=>{
				this.rules[item] = this.rulesAll[item];
			})
		},
		submit(){
			let _this = this;
			this.$refs.uForm.validate().then(res => {
				this.saveBtn();
			}).catch(errors => {
				this.$util.showToast({title:'请完善信息'})
			})
		},
		saveBtn(){
			let data = this.$util.setSaveFormData(this.formKeys,'',this.formData);
			this.$http.sendRequest({
				url: '/annual/report/overduepay/overwrite',
				method: 'PUT',
				data: {
					regno: this.regnoInfo.regno,
					ancheyear: this.year,
					overduepayList: [data]
				}
			})
			.then(res=>{
				this.setRecord();
			})
			.catch(err=>{})
		},
		
		
		//存一下记录
		setRecord(){
			let fillingItem = this.$minFormType.get(this.minFormName);
			this.$http.sendRequest({
				url: '/annual/report/record',				method: 'POST',				data: {					regno: this.regnoInfo.regno,					year: this.year,					fillingItem: fillingItem,					isImp: '0',				},
				hideLoad: true,
			})
			.then(res=>{
				uni.navigateBack();
			})
			.catch(err=>{})
		},
		goPage(path){
			uni.navigateTo({
				url: path
			})
		},
	}
}
</script>

<style lang="scss">
.wrap{
	width: 100vw;
	min-height: 100vh;
	padding-top: 16rpx;
	box-sizing: border-box;
	position: relative;
	background-color: #FFF;
	
	.topBc{
		height: 10rpx;
		background-color: #F5F6F8;
	}
}

.content{
	padding: 30rpx 36rpx;
	background-color: #FFF;
	
	.title{
		color: #E4B269;
		font-size: 36rpx;
		font-weight: bold;
		border-left: 8rpx solid #E4B269;
		line-height: 40rpx;
		padding-left: 16rpx;
		margin-bottom: 30rpx;
		margin-top: 30rpx;
	}
}



</style>